package com.hmsm.server.util;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.ss.formula.functions.T;
/**
 * 
 *  @描述:对集合数据分页
 *  @作者:luoc
 *  @创建日期:2014-4-2 下午05:11:45  
 *
 */
@SuppressWarnings({ "hiding", "serial" })
public class PageUtil<T> implements Serializable {
	/**
	 * 
	 *  @描述:
	 *  @方法名称 :getResultList
	 *  @作者     :luoc
	 *  @创建日期 :2014-4-2 上午10:37:58 
	 *  @param index
	 *  @param maxresult
	 *  @param totalPage
	 *  @param count
	 *  @return
	 *
	 */
	public QueryResult<T> getResultList(int nowPage, int maxresult, List<T> lists) {
		if (nowPage == 0 || maxresult == 0 ) {
			nowPage = 1;
			maxresult = 30;
		}
		if (nowPage <= 0) {
			nowPage = 1;
		}
		if (maxresult <= 0) {
			maxresult = 30;
		}
		QueryResult<T> list = new QueryResult<T>();
		int count = lists.size();  
        int allPages = (count - 1) / maxresult + 1; 
        List<T> resultlist=new ArrayList<T>();
        for(int i = (nowPage - 1) * maxresult; i < count && i < nowPage * maxresult; i++) { 
        	T dto = lists.get(i);
        	resultlist.add(dto);
        }  
        list.setResultlist(resultlist); 
		list.setAllPages(allPages);
		list.setNowPageNumber(nowPage);
		list.setNowViewRecordNumber(resultlist.size());
		list.setPerPageNumber(maxresult);
		list.setTotalrecord(count);
		return list;
	}

}
